<template>
  <transition name="dialog-fade">
    <el-dialog
      v-if="showDialog"
      :title="dialogTitle"
      class="dialog-component"
      :visible.sync="showDialog"
      width="700px"
    >
      <el-form
        ref="formInfo"
        :model="formInfo"
        class="demo-form-inline"
        label-width="100px"
      >
      <el-form-item label="任务名称：" prop="taskName" required>
          <el-input v-model="formInfo.taskName"></el-input>
        </el-form-item>
        <el-form-item label="域名：" prop="domainName" required>
          <el-input v-model="formInfo.domainName" placeholder="请输入域名">
          <template #prepend>Http://</template>
        </el-input>
        </el-form-item>
        <!-- <el-form-item label="关键词：" prop="keyWords" required>
          <el-input v-model="formInfo.keyWords"></el-input>
        </el-form-item> -->

        <el-form-item label="更新模式：" prop="updateMode" required>
          <el-select v-model="formInfo.updateMode" placeholder="请选择更新模式">
        <el-option label="全量模式" value="全量"></el-option>
        <el-option label="增量模式" value="增量"></el-option>
      </el-select>
        </el-form-item>
        <el-form-item label="优先级：" prop="priority" required>
          <el-select v-model="formInfo.priority" placeholder="请选择优先级">
        <el-option label="低" value="低"></el-option>
        <el-option label="中" value="中"></el-option>
        <el-option label="高" value="高"></el-option>
      </el-select>
        </el-form-item>
        <!-- <el-form-item label="爬取深度：" prop="crawlingDepth" required>
          <el-input v-model="formInfo.crawlingDepth"></el-input>
        </el-form-item> -->
        <!-- <el-form-item label="采集频率：" prop="crawlingFrequency" required>
          <el-input v-model="formInfo.crawlingFrequency"></el-input>
        </el-form-item> -->
        <el-form-item style="text-align: right;">
          <el-button type="primary" @click="submitForm(formInfo)"
            >确定</el-button>
          <el-button @click="closeDialog(0)">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </transition>
</template>
 
<script>


export default {
 name: "ComponentsDiag",
  props: {
    dialogTitle: {
      type: String,
      default: "",
    },
    itemInfo: {
      type: Object,
      default: function () {
        return {};
      },
    },
  },
  data() {
    return {
      showDialog: false,
      formInfo: JSON.parse(JSON.stringify(this.itemInfo)),
    };
  },
  methods: {
    // 保存操作
    closeDialog(flag) {
      this.showDialog = false;
      this.$emit("closeDialog", flag);
    },
    submitForm(formName) {
      const that = this;
      console.log('formName',formName);
      that.$refs["formInfo"].validate((valid) => {
        if (valid) {
          // 走保存请求
          that.$message({
            message: "操作成功！",
            type: "success",
          });
          this.post(formName.commitUrl,formName)
          that.closeDialog(1);
        } else {
          return false;
        }
        window.location.reload();
      });
    },
    async post(url,formName) {
      const { data: res } = await this.$axios.post(url, {
        taskName:formName.taskName,
        keywords:formName.keyWords,
        updateMode:formName.updateMode,
        priority:formName.priority,
        crawlingDepth:formName.crawlingDepth,
        crawlingFrequency:formName.crawlingFrequency,
        taskState:0,
        userID:formName.userID,
        crawlerType:formName.crawlerType,
        domainUrls:formName.domainName
      })
      console.log(res);
    }
   
  },
  mounted(){
      console.log('iteminfo',this.formInfo);
  }
};


</script>
 
<style scoped lang="scss">
.demo-form-inline{
  margin-left: 0px;
}
.dialog-fade-enter-active {
  -webkit-animation: dialog-fade-in 0.3s;
  animation: dialog-fade-in 0.3s;
}
.dialog-fade-leave-active {
  -webkit-animation: dialog-fade-out 0.3s;
  animation: dialog-fade-out 0.3s;
}
@-webkit-keyframes dialog-fade-in {
  0% {
    -webkit-transform: translate3d(0, -20px, 0);
    transform: translate3d(0, -20px, 0);
    opacity: 0;
  }
  100% {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    opacity: 1;
  }
}
@keyframes dialog-fade-in {
  0% {
    -webkit-transform: translate3d(0, -20px, 0);
    transform: translate3d(0, -20px, 0);
    opacity: 0;
  }
  100% {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    opacity: 1;
  }
}
@-webkit-keyframes dialog-fade-out {
  0% {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    opacity: 1;
  }
  100% {
    -webkit-transform: translate3d(0, -20px, 0);
    transform: translate3d(0, -20px, 0);
    opacity: 0;
  }
}
@keyframes dialog-fade-out {
  0% {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    opacity: 1;
  }
  100% {
    -webkit-transform: translate3d(0, -20px, 0);
    transform: translate3d(0, -20px, 0);
    opacity: 0;
  }
}
</style>